
#pragma once
#include <AVUIFrameworkElement.h>

namespace AVUI {

class ImageBrush;
class BitmapImage;

class Image : public FrameworkElement
{
public:

    DECLARE_ELEMENT(Image, FrameworkElement);

    DECLARE_DEPENDENCY_PROPERTY_BEGIN(Source);
        DECLARE_ATTRIBUTE_CONTENTPROPERTY();
    DECLARE_DEPENDENCY_PROPERTY_END();
    TRefCountedPtr<BitmapImage> get_Source() { return (BitmapImage*)(Object*)GetValue(get_SourceProperty()); }
    void set_Source(BitmapImage* pValue) { return SetValue(get_SourceProperty(), (Object*)pValue); }

    DECLARE_DEPENDENCY_PROPERTY(Stretch);
    Stretch::Enum get_Stretch() { return (Stretch::Enum)(AVUI::UnboxValue<int>(GetValue(get_StretchProperty()))); }
    void set_Stretch(Stretch::Enum value) { SetValue(get_StretchProperty(), AVUI::BoxValue<int>(value)); } 

    DECLARE_DEPENDENCY_PROPERTY(StretchDirection);
    StretchDirection::Enum get_StretchDirection() { return (StretchDirection::Enum)(AVUI::UnboxValue<int>(GetValue(get_StretchDirectionProperty()))); }
    void set_StretchDirection(StretchDirection::Enum value) { SetValue(get_StretchDirectionProperty(), AVUI::BoxValue<int>(value)); } 

    Image() { }
    virtual ~Image();


private:
    static void StaticConstructor();

    Size MeasureArrangeHelper(const Size& inputSize);
    Size MeasureOverride(const Size& constraintSize);
    Size ArrangeOverride(const Size& constraintSize);
    void OnRender(DrawingContext& drawingContext);
    void OnSourceDownloaded(Object* pSender, EventArgs* pE);

 

    static void OnSourceChanged(DependencyObject* pDO, DependencyPropertyChangedEventArgs* e);

    TRefCountedPtr<ImageBrush> m_pBrush;
};


}; // namespace AVUI
